import React, { PureComponent,Fragment } from "react";
import { connect } from "dva";
import moment from "moment";
import { Row, Col, Table, Spin, Card } from "antd";

const columns = [{
  title: '时间',
  dataIndex: 'createTime',
  render: text => moment(text).format("YYYY-MM-DD HH:mm")
},{
  title: '操作员',
  dataIndex: 'username',
},{
  title: '内容',
  dataIndex: 'ologCon',
},{
  title: 'IP',
  dataIndex: 'ip',
}];


@connect(({ equipment_integrated,global, loading }) => ({
  dictionaries:global.dictionaries,
  tableData: equipment_integrated.log.operation,
  loading: loading.models.equipment_integrated,
}))


export default class Operationlog extends PureComponent {
  constructor(props) {
    super(props);
    this.detailInfoId = this.props.match.params.id && this.props.match.params.id!='detail' ? this.props.match.params.id : 0;
    this.state={
      currentPage: 1,
      pageSize: 10,
    }
  }

  componentDidMount() {
    const {currentPage,pageSize} = this.state;
    this.getDataList(pageSize,currentPage)
  }

  getDataList(pageSize,currentPage) {
    const { dispatch } = this.props;
    dispatch({
      type: 'equipment_integrated/fetch_operation_log',
      payload: {
        devId:this.detailInfoId,
        pageSize,
        currentPage
      },
    });
  }

  // 分页、排序、筛选变化时触发
  handleTableChange = (pagination, filtersArg, sorter) => {
    const { pageSize } = this.state;

    this.setState({
      currentPage:pagination.current
    },()=>{
      this.getDataList(pageSize,pagination.current);
    })

  };


  render() {
    const { tableData,loading } = this.props;

    return (
      <Card bodyStyle={{padding:0}} >
        <Table
          columns={columns}
          dataSource={tableData && tableData.list ? tableData.list : []}
          pagination={tableData && tableData.pagination}
          onChange={this.handleTableChange}
          loading={loading}
          rowKey={"logId"}
        />
      </Card>

    );
  }
}
